{% extends "base.html" %}

{% block css %}
    <style>
        #cen {
            text-align: center;
        }

        a:hover {
            color: red;
        }

        .env-name {
            max-width: 200px;
            word-wrap: break-word;
            text-overflow: ellipsis;
            white-space: nowrap;
            overflow: hidden;
        }

        .env-name:hover {
            white-space: normal;
            overflow: auto;
        }

        tr:hover {
            background-color: #e7e7e7;
        }
    </style>
{% endblock %}

{% block nav %}
    {% for foo in model_list %}
        <li><a href="{{ foo.url }}"><i class="{{ foo.icon }}"></i>{{ foo.model_name }}</a>
        </li>
    {% endfor %}

{% endblock %}

{% block crumbs %}
    <div class="row">
        <div class="col-md-12">
            <ol class="breadcrumb">
                <li class="active">
                    <a class="this-page" href="{% url 'base:report_page' %}">运行报告</a>
                </li>
            </ol>

        </div>
    </div>
{% endblock %}

{% block body %}

    <div class="row">
        <div class="col-md-12">
            <div class="panel">
                <div class="panel-body">
                    <table class="table table-bordered">
                        <thead>
                        <tr>
                            <th id="cen">ID</th>
                            <th id="cen">测试报告名称</th>
                            <th id="cen">运行时长</th>
                            <th id="cen">用例数量</th>
                            <th id="cen">接口通过数量</th>
                            <th id="cen">接口失败数量</th>
                            <th id="cen">接口错误数量</th>
                            <th id="cen">所属计划/任务</th>
                            <th id="cen">创建时间</th>
                            <th id="cen">创建用户</th>
                            <th id="cen">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for env in object_list %}
                            <tr>
                                <td id="cen" class="report_id">{{ env.report_id }}</td>
                                {% ifequal env.make 1 %}
                                    {% if env.error_num %}
                                        <td class="env-name"
                                            style="background-color: #FFECF5">{{ env.report_name }}</td>
                                    {% else %}
                                        {% if env.fail_num %}
                                            <td class="env-name"
                                                style="background-color: #FFFFDF">{{ env.report_name }}</td>
                                        {% else %}
                                            <td class="env-name"
                                                style="background-color: #ECFFFF">{{ env.report_name }}</td>
                                        {% endif %}
                                    {% endif %}

                                {% else %}
                                    <td class="env-name">{{ env.report_name }}</td>
                                {% endifequal %}
                                <td id="cen">{{ env.totalTime }}</td>
                                <td id="cen">{{ env.case_num }}</td>
                                <td id="cen">{{ env.pass_num }}</td>
                                <td id="cen">{{ env.fail_num }}</td>
                                <td id="cen">{{ env.error_num }}
                                    {% if env.plan %}
                                        <td id="cen" class="env-name">{{ env.plan }}</td>
                                    {% else %}
                                        <td id="cen" class="env-name">{{ env.task }}</td>
                                    {% endif %}
                                <td id="cen">{{ env.update_time }}</td>
                                <td id="cen">{{ env.update_user }}</td>
                                <td id="cen">
                                    <a href="{% url 'base:report' %}?report_id={{ env.report_id }}&&page={{ page }}"
                                       class="layui-btn layui-btn-danger layui-btn-xs">
                                        <i class="fa fa-bar-chart"></i>&nbsp;&nbsp;&nbsp;
                                    </a>
                                    <a href="{% url 'base:report_logs' %}?report_id={{ env.report_id }}"
                                       class="layui-btn layui-btn-danger layui-btn-xs">
                                        <i class="fa fa-file-text-o"></i>&nbsp;&nbsp;&nbsp;</a>
                                    {% ifequal env.make 1 %}
                                        <a href="{% url 'base:file_download' %}?report_id={{ env.report_id }}"
                                           class="layui-btn layui-btn-danger layui-btn-xs"
                                           onclick="return download_btn()"><i
                                                class="fa fa-cloud-download"></i>&nbsp;
                                        </a>
                                    {% endifequal %}

                                    <a href="{% url 'base:report_delete' %}?report_id={{ env.report_id }}&&page={{ page }}"
                                       class="layui-btn layui-btn-danger layui-btn-xs"
                                       onclick="return delete_btn()"><img
                                            src="/static/admin/img/icon-deletelink.svg"/>&nbsp;&nbsp;&nbsp;
                                    </a>
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                    {% if url %}
                        <p style="font-size: 20px;font-weight: 700;">点击链接下载报告：<a href="{{ url }}">{{ url }}</a></p>
                    {% endif %}
                    <span style="color: red; font-size: 12px">{{ error }}</span>
                </div>
                {% if is_paginated %}
                    <ul class="pagination">
                        {% if first %}
                            <li class="page"><a href="?plan_id={{ plan_id }}&page=1">1</a></li>
                        {% endif %}
                        {% if left %}
                            {% if left_has_more %}
                                <li class="page"><a href="javascript:void(0)">...</a></li>
                            {% endif %}
                            {% for i in left %}
                                <li class="page"><a href="?plan_id={{ plan_id }}&page={{ i }}">{{ i }}</a></li>
                            {% endfor %}
                        {% endif %}
                        <li class="page"><a href="javascript:void(0)" class="active"> {{ page_obj.number }}</a></li>
                        {% if right %}
                            {% for i in right %}
                                <li class="page"><a href="?plan_id={{ plan_id }}&page={{ i }}">{{ i }}</a></li>
                            {% endfor %}
                            {% if right_has_more %}
                                <li class="page"><a href="javascript:void(0)">...</a></li>
                            {% endif %}
                        {% endif %}
                        {% if last %}
                            <li class="page"><a
                                    href="?plan_id={{ plan_id }}&page={{ paginator.num_pages }}">{{ paginator.num_pages }}</a>
                            </li>
                        {% endif %}

                    </ul>
                {% endif %}
            </div>
        </div>
    </div>

{% endblock %}

{% block javascript %}
    <script>
        //删除
        function delete_btn() {
            if (window.confirm("你确定要删除吗？")) {
                return true;//确定返回真
            }
            else {
                return false;//取消返回假
            }
        }
        //删除
        function download_btn() {
            if (window.confirm("下载HttpRunner报告前，请先执行测试计划~~~")) {
                return true;//确定返回真
            }
            else {
                return false;//取消返回假
            }
        }
    </script>
{% endblock %}